import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ParamsConst } from "../../../common/global/ParamsConst";
import { ProxyType } from "../../../common/global/ProxyType";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { HolidaySignRenderGetBtn } from "./HolidaySignRenderGetBtn";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { HolidaySignData } from "./HolidaySignData";
import { ItemConfig } from "../../resource/ItemConfig";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { LoaderPriority } from "../../../../com/gengine/resource/LoaderPriority";
import { ESignStatus } from "../../../../Message/Public/ESignStatus";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { Language } from "../../../../extend/language/Language";
import { GameConst } from "../../../component/gconst/GameConst";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
//class HolidaySignRender
    
    export  class HolidaySignRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            this._frontSp = new Object /* flash.display.Sprite */();
            addChild(this._frontSp);
            this._frontBm = ObjCreate.createBitmap("", 6, 4, this._frontSp);
            this._itemBorderBg = ObjCreate.createBitmap("", 2, 2, this._frontSp);
            this._dateBm = ObjCreate.createBitmap("", 0, 0, this._frontSp);
            if (ParamsConst.instance.proxyType == ProxyType.TW) 
            {
                DisplayUtil.removeMe(this._dateBm);
            }
            this._backBm = ObjCreate.createBitmap("", 2, 2, this);
            this._getBtn = new HolidaySignRenderGetBtn();
            this._getBtn.x = 21;
            this._getBtn.y = 150;
            addChild(this._getBtn);
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClick);
            LoaderHelp.addResCallBack(ResFileConst.Illustrate, this.onResLoaded);
            LoaderHelp.addResCallBack(ResFileConst.holidaySign, this.onHolidaySignResLoaded);
            return;
        }

        /* internal  */onHolidaySignResLoaded(): void
        {
            this._load = true;
            this.setDateBm();
            this._backBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.holidaySignBack2015);
            return;
        }

        /* internal  */setDateBm(): void
        {
            if (this._holidaySignData && this._load) 
            {
                this._dateBm.bitmapData = GlobalClass.getBitmapData("holidaySignzheng" + this._holidaySignData.tHolidaySign.id);
            }
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._itemBorderBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.illustrateCardBg);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this._holidaySignData = arg1 as HolidaySignData;
            if (this._holidaySignData) 
            {
                this.setDateBm();
                loc1 = ItemConfig.instance.getInfoByCode(this._holidaySignData.tHolidaySign.itemCode);
                if (loc1) 
                {
                    this._imagesName = loc1.item.effectEx + ".jpg";
                    LoaderManager.instance.load(this._imagesName, this.onLoadCompleteHandler, LoaderPriority.LevelA);
                }
                else 
                {
                    this._frontBm.bitmapData = null;
                }
                this._getBtn.updateState(this._holidaySignData.btnStatus);
                if (this._holidaySignData.btnStatus != ESignStatus._ESignDone) 
                {
                    this._frontSp.visible = false;
                    this._backBm.visible = true;
                }
                else 
                {
                    this._frontSp.visible = true;
                    this._backBm.visible = false;
                }
            }
            else 
            {
                this.clean();
            }
            return;
        }

        /* internal  */clean(): void
        {
            this._getBtn.updateState(-1);
            this._getBtn.disposeLightMask();
            return;
        }

        /* internal  */onCompleteHandler(): void
        {
            this._backBm.visible = false;
            return;
        }

        /* internal  */onLoadCompleteHandler(arg1: ImageInfo): void
        {
            if (arg1.name == this._imagesName) 
            {
                this._frontBm.bitmapData = arg1.bitmapData;
            }
            return;
        }

        /* internal  */onGetBtnClick(arg1: Object /* flash.events.Event */): void
        {
            if (this._getBtn.state != ESignStatus._ESignSupplement) 
            {
                if (this._getBtn.state != -1) 
                {
                    this.goGetReward();
                }
            }
            else 
            {
                TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.HolidaySignSupplementStateTodayaNoTip, this.checkMoney, Language.getStringByParam(79013, GameConst.SignSupplementCost), null, Alert.OK | Alert.CANCEL, null, null, null, 4);
            }
            return;
        }

        /* internal  */checkMoney(): void
        {
            var loc1=Cache.instance.role.money.gold;
            if (loc1 >= GameConst.SignSupplementCost) 
            {
                this.goGetReward();
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(70316));
            }
            return;
        }

        /* internal  */goGetReward(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.HolidaySignGetGifBag, this._holidaySignData.tHolidaySign.id));
            return;
        }

        /* internal */ /* var */_getBtn: HolidaySignRenderGetBtn;

        /* internal */ /* var */_holidaySignData: HolidaySignData;

        /* internal */ /* var */_frontSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_frontBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_itemBorderBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_dateBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_backBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_imagesName: string="";

        /* internal */ /* var */_load: Boolean;
    }
